package com.bana.fvs.protocol;

import com.bana.fvs.code.LampSwitchStatus;

import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;

/**
 * 设置控制器联动开关状态
 */
public class SetControllerSwitch {

    public int getId()
    {
        return 0x03;
    }


    public byte[] toBuffer(int kzqbsm, int switchStatus) throws IOException {

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        DataOutputStream dos = new DataOutputStream(baos);
        dos.writeByte(0x81);
        dos.writeByte(kzqbsm);
        dos.writeByte(getId());
        dos.writeByte(switchStatus== LampSwitchStatus.Close?0x09:0x08);
        dos.writeByte(0xFF);
        byte[] buffer= baos.toByteArray();
        dos.close();
        baos.close();
        return buffer;
    }

    public boolean toResult(byte[] buffer)
    {
        return buffer.length==4;
    }
}
